<template>
  <div class="shopList">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>商铺列表</span>
        <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
      </div>
      <div class="content">
        <div class="left">
          <span>店铺名：</span>
          <el-input v-model="value1" placeholder="请输入" class="ipt" />
        </div>
        <div class="right">
          行业：
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.industryName"
              :value="item.industryName"
            />
            <el-option value="" />
          </el-select>
        </div>
        <el-row type="flex">
          <el-col style="margin-right:10px">
            <el-button size="small" type="primary" @click="query">查询</el-button>
          </el-col>
          <el-col>
            <el-button size="small" @click="reset">重置</el-button>
          </el-col>
        </el-row>
      </div>
      <el-button type="primary" icon="el-icon-plus" size="small" @click="addShop">新增</el-button>
      <el-table ref="multipleTable" style="margin-top:10px;width: 100%" :data="shopList" tooltip-effect="dark">
        <el-table-column type="selection" width="55" />
        <el-table-column label="店铺名称" prop="shopName" />
        <el-table-column label="行业" prop="industryName" />
        <el-table-column label="地址" prop="address" />
        <el-table-column label="电话" prop="tel" />
        <el-table-column label="推广人名称" prop="promoter" />
        <el-table-column label="权益级别" prop="equitiesName" />
        <el-table-column label="权益时效" prop="equitiesTime" />
        <el-table-column label="销售额" prop="sale" />
        <el-table-column label="状态" prop="status" />
        <el-table-column label="性质" prop="nature" />
        <el-table-column label="备注" prop="remark" show-overflow-tooltip />
        <el-table-column label="操作">
          <template slot-scope="{row}">
            <el-dropdown @command="handleCommand($event,row)">
              <span class="el-dropdown-link">
                操作<i class="el-icon-arrow-down el-icon--right" />
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="详情">详情</el-dropdown-item>
                <el-dropdown-item command="查看商品">查看商品</el-dropdown-item>
                <el-dropdown-item command="经营分析">经营分析</el-dropdown-item>
                <el-dropdown-item command="启用">启用/停用</el-dropdown-item>
                <el-dropdown-item command="删除" divided>删除</el-dropdown-item>
                <el-dropdown-item command="编辑" divided>编辑</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>

      <el-row type="flex" justify="center" align="middle" style="height: 60px">
        <el-pagination
          layout="total, prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"

          :current-page="page.page"
          @current-change="handleCurrentChange"
        />
      </el-row>
    </el-card>
    <add-shop v-if="showAddDialog" :show-add.sync="showAddDialog" :date.sync="currentData" @addShop="addShops($event)" />
  </div>
</template>

<script>
import addShop from './component/add-shop'
import { getShopList, delShop, getIndustry, queryIndustry, equities } from '@/api/shopList'
export default {
  name: 'ShopList',
  components: {
    addShop
  },
  data() {
    return {
      // 行业选择
      options: [],
      Equities: '', // 放置权益级别
      value: '', // 选中哪个行业
      value1: '', // 选中哪个商铺
      shopList: [], // 表格数据
      currentData: {}, // 选中当前行的数据
      page: {
        page: 1,
        pagesize: 10,
        total: 0
      },
      showAddDialog: false
    }
  },
  created() {
    this.getShopList()
    this.getIndustry()
    this.equities()
  },
  methods: {
    addShop() {
      this.showAddDialog = true
    },
    handleCommand(command, row) {
      if (command === '详情') {
        this.showAddDialog = true
        this.currentData = row
      } else if (command === '删除') {
        this.delShop(row.id)
      } else if (command === '编辑') {
        this.showAddDialog = true
        this.currentData = row
      }
    },
    async getShopList() {
      const { data } = await getShopList(this.page)
      console.log(data.data)
      this.page.total = data.total
      this.shopList = data.data
    },
    handleCurrentChange(page) {
      this.page.page = page
      this.getShopList()
    },
    delShop(id) {
      this.$confirm('是否删除数据').then(async() => {
        await delShop(id)
        this.getShopList()
      })
    },
    addShops(value) {
      this.showAddDialog = value
      this.getShopList()
    },
    // 获取行业
    async getIndustry() {
      const { data } = await getIndustry()
      console.log(data)
      this.options = data.data
    },
    // 按条件查询
    async query() {
      if (this.value && this.value1) {
        const { data } = await queryIndustry({ industryId: this.value, shopName: this.value1 })
        console.log(data)
        this.shopList = data.data
      } else {
        console.log(22)
        const { data } = await queryIndustry()
        this.shopList = data.data
      }
    },
    /**
     * 根据获取所有权益
     */
    async equities() {
      const { data } = await equities()
      this.Equities = data.data
    },
    reset() {
      this.value = ''
      this.value1 = ''
    }
  }
}
</script>

<style lang="less" scoped>
.box-card{
  margin-top: 30px;
}
.content{
  display: flex;
  .left{
    font-weight: 400;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 350px;
    margin-left: 80px;
}
.right{
  width: 300px;
  margin-left: 50px;
   font-weight: 400;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
}
span{
  width: 70px;
}
}

</style>
